<%@ page import="ml.kgc.service.NewsService" %>
<%@ page import="ml.kgc.service.impl.NewsServiceImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="ml.kgc.pojo.News" %>
<%@ page import="ml.util.PageSupport" %>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%--动态包含包含结果(会报错)--%>
<%--<jsp:include page="../common/common.jsp"></jsp:include>--%>
<%@ include file="../common/common.jsp"%><%--静态包含，直接拿过来用--%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>无标题文档</title>
<script>
    function addNews(){
        window.location="newsDetailCreateSimple.jsp";//窗口地址调到xx页面
    }
</script>
</head>

<body>
<!--主体-->
    <div class="main-content-right">
        <!--即时新闻-->
        <div class="main-text-box">
            <div class="main-text-box-tbg">
                <div class="main-text-box-bbg">
                    <form name ="searchForm" id="searchForm" action="${pageContext.request.contextPath}/news/jsp/admin/newsDetailList.jsp" method="post">
		 	          <div>
		 				新闻分类：
		 					<select name="categoryId">
		 						<option value="0">全部</option>
			        			
			        				<option value='1' >国内</option>
			        			
			        				<option value='2' >国际</option>
			        			
			        				<option value='3' >娱乐</option>
			        			
			        				<option value='4' >军事</option>
			        			
			        				<option value='5' >财经</option>
			        			
			        				<option value='6' >天气</option>
			        			
	        				</select>
		 				新闻标题<input type="text" name="title" id="title" value=''/>
		 					<button type="submit" class="page-btn">GO</button>
		 					<button type="button" onclick="addNews();" class="page-btn">增加</button>
		 					<input type="hidden" name="currentPageNo" value="1"/>
		 					<input type="hidden" name="pageSize" value="10"/>
		 					<input type="hidden" name="totalPageCount" value="2"/>
		 	</div>
		 	</form>
			<table cellpadding="1" cellspacing="1" class="admin-list">
				<thead >
					<tr class="admin-list-head">
						<th>新闻标题</th>
                        <th>作者</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                <%
                    //可以用的javaBean代替new(此标签放在页面顶部)
                    //<jsp:useBean id="newsService" class="ml.kgc.service.impl.NewsServiceImpl"></jsp:useBean>
                    //NewsService newsService = new NewsServiceImpl();
                    //分页查询并显示
                    String currentPage = request.getParameter("pageIndex");
                    if(currentPage == null || currentPage.equals("")){ //首次访问该页面
                        currentPage = "1";
                    }
                    int pageIndex = Integer.parseInt(currentPage);//当前页码
                    int totalCount = newsService.getTotalCount();//获取新闻总数量
                    int pageSize = 2;//页面容量
                    PageSupport pageSupport = new PageSupport();
                    pageSupport.setCurrentPageNo(pageIndex);
                    pageSupport.setPageSize(pageSize);
                    pageSupport.setTotalCount(totalCount);//查询总页数
                    int totalPage = pageSupport.getTotalPageCount();//获取总页数
                    //控制首页和尾页
                    if(pageIndex<1){
                        pageIndex = 1;
                    }else if(pageIndex>totalPage){
                        pageIndex = totalPage;
                    }

                    //List<News> list = newsService.getNewsList();
                    List<News> list = newsService.getPageNewsList(pageIndex,pageSize);
                    int i =0;
                    for(News news:list){
                        i++;
                %>
                <%--隔行变色--%>
                    <tr <%if(i%2==0){ %>class="admin-list-td-h2"<%}%>>
                        <td><a href="newsDetailView.jsp?id=<%=news.getId()%>"><%=news.getTitle()%></a></td>
                        <td><%=news.getAuthor()%></td>
                        <td><%=news.getCreateDate()%></td>
                        <td>修改</td>
                    </tr>
                <%}%>
                </tbody>
            </table>
           <div class="page-bar">
			<ul class="page-num-ul clearfix">
				<li>共<%=totalCount%>条记录&nbsp;&nbsp; <%=pageIndex%>/<%=totalPage%>页</li>&nbsp;
                <%
                    if(pageIndex>1){
                %>
                <a href="newsDetailList.jsp?pageIndex=1">首页</a>
                <a href="newsDetailList.jsp?pageIndex=<%=pageIndex-1%>">上一页</a>
                <%} if(pageIndex<totalPage){%>&nbsp;
                <a href="newsDetailList.jsp?pageIndex=<%=pageIndex+1%>">下一页</a>
                <a href="newsDetailList.jsp?pageIndex=<%=totalPage%>">尾页</a>&nbsp;
                <% }%>
                <%--<a href="javascript:page_nav(document.forms[0],2);">首页</a>
                <a href="javascript:page_nav(document.forms[0],2);">上一页</a>&nbsp;
                <a href="javascript:page_nav(document.forms[0],2);">下一页</a>
				<a href="javascript:page_nav(document.forms[0],2);">尾页</a>&nbsp;--%>
			</ul>
		 <span class="page-go-form"><label>跳转至</label>
	     <input type="text" name="inputPage" id="inputPage" class="page-key" />页
	     <button type="button" class="page-btn" onClick='jump_to(document.forms[0],document.getElementById("inputPage").value)'>GO</button>
		</span>
		</div> 
        </div>
       </div>
   </div>
   </div>
</body></html>